package com.oocl.service;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import com.oocl.struct.Customer;

public class SetServices {
	private Set<Customer> set;
	public SetServices() {
		set = new TreeSet<Customer>();
	}
	
	public void addCustomer(Customer customer){
		set.add(customer);
	}
	
	public Set<Customer> sortByBirth(){
		return null;
		
	}
	
	public void printById(){
		System.out.println("ID\tName\tEmail\t\tSex\tBirthday");
		for(Customer customer:set){
			System.out.println(customer.toString());
		}
	}
	
	public void printByBirth() throws CloneNotSupportedException{
		Set<Customer> newset = new TreeSet<Customer>(new BirthComparator());
		for(Customer customer:set){
			Customer cloneCustomer = (Customer) customer.clone();
			newset.add(cloneCustomer);
		}
		System.out.println("ID\tName\tEmail\t\tSex\tBirthday");
		for (Customer customer : newset) {
			System.out.println(customer.toString());
		}
		
	}
	
	public void printXML(){
		System.out.println("<customers>");
		for(Customer customer:set){
			System.out.println("\t<customer id='"+customer.getId()+"'>");
			System.out.println("\t\t<name>"+customer.getName()+"</name>");
			System.out.println("\t\t<birthday>"+customer.getBirthday()+"</birthday>");
			System.out.println("\t\t<sex>"+customer.isSex()+"</sex>");
			System.out.println("\t\t<email>"+customer.getEmail()+"</email>");
			System.out.println("\t</customer>");
		}
		System.out.println("</customers>");
	}

}
